<?php
@session_start();
$PurviewLevel=2;
$CheckChannelID=0;  
$PurviewLevel_Others="yingxiao_hudong_youhuiquan";
require("../../inc/common.inc.php");
require_once("../Admin_ChkPurview.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$wheresql="";
$yhqid=intval($yhqid);
if ($yhqid>0){
	$yhqinfo=$db->getinfo("select * from mx_vpp_youhuiquan where id='$yhqid'");
	if (!is_array($yhqinfo)){
		$fun->popmassage("请正确选择要查看的优惠券","","popback");
		exit();
	}
	$wheresql=" and yhqid='$yhqid' ";
}
?>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link rel="stylesheet" href="../images/style.css" type="text/css">
</head>
<body> 
<div class="right">
<?php
require("../mx_head.php");
if ($actions=="setisuse"){
    $id=intval($id);
	if($id==""){
		$fun->popmassage("请选择要使用的优惠券","","popback");
		exit();
	}
	$db->excu("update mx_vpp_lingqu_yhq  set isuse='1',usedate='".date("Y-m-d H:i:s")."',setuseid='".$_SESSION['mxadmin']['userid']."' where id='$id' and isuse='0'");

	$url=$fromurl?$fromurl:$FROMURL;
	jump2("操作成功",$url,1);
	exit();
}
?>
<div class="gk">
    <div class="ti2 fl">优惠券领取管理</div>
    <ul class="fr">
        <li><span class="c1"><?php $znum=$db->listcount("mx_vpp_lingqu_yhq","");echo $znum;?></span><span>总条数</span></li>
    </ul>
    <div class="clear"></div>
</div>
<div class="height15"></div>
<div class="xm2">
<h1 class="fl">优惠券领取管理</h1>
</div>
<div class="xm2_b" style="border-bottom:0px;">

<div class="t">
<table border="0" cellpadding="0" cellspacing="1" class="search_from">
<form name="form2" action="yx_vpp_lingqu_yhq.php" method="get">
 <tr>
   <td>&nbsp;优惠券号：</td><td><input name="keywords" type="text" id="keywords" value="" size="10" class="search_input"/></td>
   <td>&nbsp;用户名：</td><td><input name="username" type="text" id="username" value="" size="10" class="search_input"/></td>
  <td>&nbsp;领取时间：</td>
  <td><input name="mindate" type="text" id="mindate" value="" size="10" class="search_input">
	  <script language="javascript" type="text/javascript">
	  Calendar.setup({
	  	  inputField     :    "mindate",
	  	  ifFormat       :    "%Y-%m-%d",
	  	  showsTime      :    false,
	  	  timeFormat     :    "24"
	  });
	  </script>
	  —
	  <input name="maxdate" type="text" id="maxdate" value="" size="10" class="search_input">
	  <script language="javascript" type="text/javascript">
	  Calendar.setup({
	  	  inputField     :    "maxdate",
	  	  ifFormat       :    "%Y-%m-%d",
	  	  showsTime      :    false,
	  	  timeFormat     :    "24"
	  });
	  </script>
  </td>
  <td><select name="isuse"><option value="">使用状态</option><option value="1">已使用</option><option value="0">未使用</option></select></td>
  <td><select name="pagesize"><option value="20">20条/页</option><option value="30" <?php if ($pagesize==30){echo "selected";}?>>30条/页</option><option value="50" <?php if ($pagesize==50){echo "selected";}?>>50条/页</option></select></td>
  <td><input type="hidden" name="yhqid" id="yhqid" value="<?php echo $yhqid;?>" /><input type="submit" name="Submit3" value="搜索" class="button2" /></td>
  </tr>
</form>
</table>
</div>
</div>


<div class="xm2_b">
<div class="height10"></div>
<table width="100%" border="0" cellpadding="8" cellspacing="1" class="table_southidc">
<form name="form1" method="post" action="yx_vpp_lingqu_yhq.php?action=work<?php echo "&$s"?>">
  <tr>
    <th width="6%" align="center">ID</th>
    <th width="15%" align="center">优惠券号</th>
    <th width="20%" align="center">优惠券名称</th>
    <th width="15%" align="center">有效期</th>
    <th width="12%" align="center">领取时间</th>
    <th width="10%" align="center">领取用户</th>
    <th width="10%" align="center">使用状态</th>
  </tr>
<?php
  $s="yhqid=$yhqid&";
  $str=" $wheresql ";
  if ($keywords!=""){
  	$str.=" and yhqcode like '%$keywords%'";
	$s.="keywords=".urlencode($keywords)."&";
  }
  if ($username!=""){
  	$str.=" and userid in (select id from mx_user where username like'%$username%' or realname like'%$username%') ";
	$s.="username=".urlencode($username)."&";
  }
  if ($isuse!=""){
  	$isuse=intval($isuse);
  	$str.=" and isuse='$isuse' ";
	$s.="isuse=$isuse&";
  }
  if ($mindate!=""){
  	$str.=" and createdate>='$mindate 00:00:00'";
	$s.="mindate=$mindate&";
  }
  
  if ($maxdate!=""){
  	$str.=" and createdate<='$maxdate 23:59:59'";
	$s.="maxdate=$maxdate&";
  }
	
  if(empty($pageindex)){
      $pageindex=1;
  }
  $pagesize=intval($pagesize);
  if ($pagesize<=0){$pagesize=20;}

  $table=" mx_vpp_lingqu_yhq ";
  $order=" order by createdate desc, id desc";
  $column=" * ";
  $biaoid="id";
  $c=$db->listcount($table,$str);

  $list=$db->list1($pageindex,$pagesize,$table,$column,$str,$order,$biaoid);
	
	
  if (!is_array($list) or $c==0){
  echo "<tr class=\"list\"><td colspan=8><center>暂无信息</center></td></tr>";
  }
  else{
  for($i=0;$i<count($list);$i++){
  	  if(!is_array($other_info[$list[$i]["yhqid"]])){
		  $other_info[$list[$i]["yhqid"]]= get_yhq($list[$i]["yhqid"]);
		  $thisinfo=$other_info[$list[$i]["yhqid"]];
	  }
	  else{
		  $thisinfo=$other_info[$list[$i]["yhqid"]];
	  }
  	  if(!is_array($user_info[$list[$i]["userid"]])){
		  $user_info[$list[$i]["userid"]]=$db->getuserinfo($list[$i]["userid"]);
		  $thisuserinfo=$user_info[$list[$i]["userid"]];
	  }
	  else{
		  $thisuserinfo=$user_info[$list[$i]["userid"]];
	  }
	  $list[$i][isuse]=$list[$i][isuse]?'<span style="color:#FF0000" title="使用日期：'.$list[$i]["usedate"].'">已使用</span>':"<A HREF=\"javascript:set_user('".$list[$i]["id"]."');\" style='color:blue;' title=设为使用>未使用</A>";
  ?>
  <tr class="list"> 
    <td align="center"><?php echo $list[$i][id]?></td>
    <td align="center"><?php echo $list[$i]["yhqcode"]?></td>
    <td><?php echo $thisinfo[name]?></td>
    <td align="center"><?php echo $thisinfo["startdate"]." - ".$thisinfo["enddate"];?></td>
    <td align="center"><?php echo $list[$i][createdate]?></td>
    <td align="center"><?php echo $thisuserinfo["realname"] ?></td>
    <td align="center"><?php echo $list[$i]["isuse"];?></td>
  </tr>
<?php
	}
	}
?>
<input type="hidden" name="jobs" value="0">
</form>
</table>
<?php if ($c>0){?>
			<div class="height15"></div>
			<!--
			<div class="do_div">
				<div class="l"><a href="javascript:CheckAll(document.form1,'all')">全选</a>&nbsp;<a href="javascript:CheckAll(document.form1,'')">反选</a></div>
				<div class="l2">
				选择操作：
				a href="javascript:postdo('isok')">审核</a>
				<a href="javascript:postdo('unisok')">取消审核</a>
				<a href="javascript:postdo('delete')"/>删除</a>
				</div>
			</div>
			-->
			<div class="clear"></div>
			<div class="pagination">
			<?PHP
			echo $db->ThePage_mxsoft($s,$pageindex,$c,$pagesize)
			?>
			</div>
<?php }?>
<div class="clear"></div>
<div class="height10"></div>
<div class="clear"></div>
<script type="text/javascript" src="/mxsoft/js/jquerys-1.5.1.js"></script>
<script language="javascript">
$(document).ready(function(){  
	$(".table_southidc tr").mouseover(function(){   
	$(this).addClass("list2");}).mouseout(function(){   
	$(this).removeClass("list2");}) //移除该行的class   
	$(".table_southidc tr:even").addClass("list1");   
});   
</script> 

<script language="javascript">
function postdo(va){
	document.form1.jobs.value=va
	document.form1.submit();
}
function set_user(id){
	if(confirm("您确定要使用此优惠券吗?")){
			document.form1.action="yx_vpp_lingqu_yhq.php?actions=setisuse&m=&yhqid=<?php echo $yhqid;?>&id="+id;
			document.form1.submit();
		
	}else{
	return;
	}
}
</script>
</div>
<?php require("../mx_foot.php");?>
</div>
</body>
</html>
<?php
function get_yhq ($id) {
	global $db;
	$sql = "select * from mx_vpp_youhuiquan where id='".$id."'" ;
	$rsdb=$db->get_one($sql);
	return $rsdb;
}
?>